//
//  XXPositionViewController.m
//  XX
//
//  Created by lly on 15/5/26.
//  Copyright (c) 2015年 lly. All rights reserved.
//

#import "XXPositionViewController.h"
#import "XXListView.h"
#import "AppMacro.h"
#import "XXAddrCell.h"
@interface XXPositionViewController ()

@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic, strong) XXListView *dtableView;
@end

#define KEY_ROW @"addresses"

#define KEY_SECTION @"city"

@implementation XXPositionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataSource = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"postionList" ofType:@"plist"]];
    

    self.edgesForExtendedLayout = NO;
    self.dtableView = [[XXListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    
    self.dtableView.delegate = self;
//    self.dtableView.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.dtableView];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSection:(XXListView *)listView
{
    return self.dataSource.count;
}

- (NSInteger)listView:(XXListView *)listView numberOfRowInSection:(NSInteger)section
{
    return [[self.dataSource[section] valueForKey:KEY_ROW] count];
}

- (UITableViewCell *)sectionListView:(XXListView *)listView cellForSection:(NSInteger)section
{
    static NSString *cellIndentifier = @"sectionDoubleCell";
    UITableViewCell *cell = (UITableViewCell *)[listView.sectionTable dequeueReusableCellWithIdentifier:cellIndentifier];
    
    if(!cell)
    {
        cell =  [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:13];
    cell.textLabel.textColor = [UIColor darkGrayColor];
    cell.textLabel.numberOfLines = 0;
    cell.selectedBackgroundView = [[UIView alloc] init];
    cell.selectedBackgroundView.backgroundColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor colorWithWhite:0.929 alpha:1.000];
    NSString *city = [self.dataSource[section] valueForKey:KEY_SECTION];
    cell.textLabel.text = city;
    return cell;
}

- (UITableViewCell *)listListView:(XXListView *)listView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndentifier = @"rowDoubleCell";
    XXAddrCell *cell = (XXAddrCell *)[listView.sectionTable dequeueReusableCellWithIdentifier:cellIndentifier];
    
    if(!cell)
    {
        cell =  [[[NSBundle mainBundle] loadNibNamed:@"XXAddrCell" owner:nil options:nil] lastObject];
    }
    cell.backgroundColor = [UIColor clearColor];

    NSString *addr = [[self.dataSource[indexPath.section] valueForKey:KEY_ROW] objectAtIndex:indexPath.row];
    cell.titleLabel.text = addr;
    return cell;
}

- (void)listView:(XXListView *)listView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (CGFloat)heightForSectionAtIndex:(NSInteger)section
{
    return 35;
}

- (CGFloat)listView:(XXListView *)listView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
